package com.zhyz.bookstore.dao.impl;

import com.zhyz.bookstore.dao.CartDao;
import com.zhyz.bookstore.entity.Book;
import com.zhyz.bookstore.entity.Cart;
import com.zhyz.bookstore.entity.Category;
import com.zhyz.bookstore.util.JDBCUtils;
import org.apache.commons.dbutils.handlers.MapHandler;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class CartDaoImpl implements CartDao {
    //返回列表
    @Override
    public List<Category> findAllCategory() {
        List<Category> list = new ArrayList<Category>();
        try {
            Connection connection = JDBCUtils.getconnection();
            PreparedStatement preparedStatement = connection.prepareStatement("select * from category");
            ResultSet rs = preparedStatement.executeQuery();
            while (rs.next()) {
                Category category = new Category();
                category.setCategoryId(rs.getString("category_id"));
                category.setCategoryName(rs.getString("category_name"));
                category.setCategoryDesc(rs.getString("category_desc"));
                list.add(category);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
